<template>
  <view class="container">
    <view class="list">
      <view v-for="item in data"  class="list-item">
        <view class="item-header" @click="toggleExpand(item.typeId)">
          <view class="item-title">
            <text class="title-text">原料类型：{{ item.typeName }}</text>
            <text class="title-subtext">创建时间: {{ item.createdAt }}</text>
          </view>
        </view>

        <view v-if="item.expanded" class="item-details">
          <view class="detail-card" v-for="child in item.children" :key="child.id">
            <view class="card-header">
              <text class="card-title">指标名称: {{ child.propertyName }}</text><br>
              <text class="card-subtitle">标准值: {{ child.startingValue }} - {{ child.endValue }} {{ child.unitName }}</text>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      data: [],
	  id: undefined
    };
  },
  onLoad(options){
	  this.id = options.id;
	  this.getData();
  },
  methods: {
    getData() {
      uni.request({
        url: 'http://127.0.0.1:1005/MaterialQualityStandardTrue/findMesMaterialQualityStandardTrue',
        method: 'GET',
		data:{
			typeId: this.id
		},
        success: (res) => {
          const result = res.data;
          if (result.code === 200 && Array.isArray(result.data)) {
            this.data = result.data.map(item => ({
              ...item,
              expanded: false,
            }));
          } else {
            console.error('Unexpected data format:', result);
          }
        },
        fail: (err) => {
          console.error('Error fetching data:', err);
        }
      });
    },
    toggleExpand(id) {
      this.data = this.data.map((item) => {
        if (item.typeId === id) {
          return {
            ...item,
            expanded: !item.expanded
          };
        }
        return item;
      });
    },
  },
};
</script>

<style>
page {
  background: #f9f9f9;
}

.container {
  padding: 32rpx;
}

.header {
  padding: 32rpx;
  background: linear-gradient(90deg, #aaa014, #68B0FF);
  border-radius: 50rpx; /* 增大圆角 */
  text-align: center;
  color: #fff;
}

.header-title {
  font-size: 24px;
  font-weight: bold;
}

.list {
  margin-top: 32rpx;
}

.list-item {
  background-color: #ffffff;
  border-radius: 12rpx;
  margin-bottom: 24rpx;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
  overflow: hidden;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.list-item:hover {
  transform: translateY(-5rpx);
  box-shadow: 0 8rpx 20rpx rgba(0, 0, 0, 0.15);
}

.item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24rpx;
  cursor: pointer;
  transition: background-color 0.3s;
}

.item-header:hover {
  background-color: #f0f6ff;
}

.item-title {
  display: flex;
  flex-direction: column;
}

.title-text {
  font-size: 18px;
  font-weight: bold;
  color: #333;
}

.title-subtext {
  font-size: 16px;
  color: #666;
  margin-top: 4rpx;
}

.icon {
  font-size: 24px;
  color: #ff0000;
  transition: transform 0.3s;
}

.expanded {
  transform: rotate(180deg);
}

.item-details {
  padding: 20rpx;
  background-color: rgba(240, 245, 250, 0.9); /* 调整背景颜色和透明度 */
  border-radius: 8rpx; /* 添加圆角 */
  box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.08); /* 添加阴影效果 */
  animation: fadeIn 0.3s ease-in-out;
  transition: all 0.3s ease; /* 增加整体过渡效果 */
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.detail-card {
  background: #ffffff;
  border-radius: 10rpx; /* 增大卡片圆角 */
  padding: 18rpx; /* 调整内边距 */
  margin-bottom: 18rpx;
  box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.06); /* 调整卡片阴影 */
  transition: transform 0.2s ease;
}

.detail-card:hover {
  transform: scale(1.03); /* 调整鼠标悬停时的缩放比例 */
}

.card-header {
  display: flex;
  flex-direction: column; /* 将弹性容器的方向改为垂直排列 */
  justify-content: flex-start; /* 垂直方向上的内容靠顶部排列 */
  align-items: flex-start; /* 水平方向上的内容靠左侧排列 */
  margin-bottom: 14rpx;
}

.card-title {
  font-size: 17px; /* 增大标题字体大小 */
  font-weight: bold;
  color: #333;
}

.card-subtitle {
	margin-top: 10px;
  font-size: 15px; /* 调整副标题字体大小 */
  color: #4080ff;
}

.card-content {
  display: flex;
  justify-content: space-between;
}

.content-text {
  font-size: 16px;
  color: #666;
}
</style>
